package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    /**
     * 新增分类
     * @param dto
     * @return
     */
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO dto){

        return categoryService.addCategory(dto);
    }


    /**
     * 条件分页查询
     * @param page 页码
     * @param pageSize 每页几条
     * @param name 分类名称
     * @param type 类型
     * @return
     */
    @GetMapping("/page")
    public Result queryByPage(@RequestParam(value = "page",defaultValue = "1")Integer page,
                              @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize,
                              @RequestParam(value = "name",required = false) String name,
                              @RequestParam(value = "type",required = false)Integer type){
        return categoryService.queryByPage(page,pageSize,name,type);
    }
}
